package com.threeox.commonlibrary.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.HorizontalScrollView;

/**
 *
 * @ClassName: CustomHorizontalScrollView
 *
 * @Description: Todo(自定义水平滚动视图，解决ScrollView在API23以下没有滚动监听事件问题)
 *
 * @author 赵屈犇
 *
 * @date 创建时间:2017/8/13 下午5:35
 * 
 * @version 1.0
 */
public class CustomHorizontalScrollView extends HorizontalScrollView {

    private onScrollChangeListener onScrollChangeListener;

    public CustomHorizontalScrollView(Context context) {
        super(context);
    }

    public CustomHorizontalScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomHorizontalScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    /**
     * 设置监听
     * @param onScrollChangeListener
     */
    public void setOnScrollChangeListener(onScrollChangeListener onScrollChangeListener) {
        this.onScrollChangeListener = onScrollChangeListener;
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        //回调
        if (onScrollChangeListener!=null){
            onScrollChangeListener.onScrollChanged(this,l,t);
        }
    }

    public interface onScrollChangeListener{
        void onScrollChanged(HorizontalScrollView scrollView,int x,int y);
    }

}
